<template>
  <div  class="page_warppers">

  <el-header>
    <div class="header">
      <el-button type="primary" @click="exit">退出</el-button>
    </div>
  </el-header>
  <el-container class="container">

    <el-aside>
        <happy-scroll resize color="rgba(0,0,0,0.5)" size="5">
          <div >
      <div class="collapse"><p @click="onCollapse">|||</p></div>
        <el-menu
        :collapse="isCollapse"
        unique-opened
      :default-active="menuIndex"
      class="el-menu-vertical-demo"
      ref="mychild"
      @select="selectMenu"
      background-color="#545c64"
      text-color="#fff"
      active-text-color="#ffd04b">
      <el-submenu :index="''+index" v-for="(item,index) in asideList" :key="item.id">
        <template slot="title">
          <span>{{item.title}}</span>
        </template>
        <el-menu-item-group v-for="(items,i) in item.submenu" :key="items.id">
          <el-menu-item :index="index+'-'+i">{{items.title}}</el-menu-item>
        </el-menu-item-group>
        <!-- <el-submenu index="1-4">
          <template slot="title">选项4</template>
          <el-menu-item index="1-4-1">选项1</el-menu-item>
        </el-submenu> -->
      </el-submenu>
    
   
    </el-menu>
    </div>
        </happy-scroll>
    </el-aside>
      <el-main >
    <router-view/>
      </el-main>
  </el-container>
  </div>
</template>

<script>
import { HappyScroll } from 'vue-happy-scroll'
  // 引入css，推荐将css放入main入口中引入一次即可。
  import 'vue-happy-scroll/docs/happy-scroll.css'
//自定义组件名
export default {
   components: {HappyScroll} ,
  data(){
    return{
      menuIndex:localStorage.getItem("menuIndex")||"0-0",
      isCollapse:false,
      width:"200px",
        asideList:[]
    }
  },created(){
    this.getHomeList();
    
    
  },
  mounted(){
  },
    methods: {
    getHomeList(){
  this.$api.getlogin("/api/rule","")
          //  this.$http.post("log",{username:123456,password:123456})
            .then(res=>{
                if(res.data.code==200){
                  
                 this.asideList =res.data.data;
                 
                };
                
            }).catch(error=>{

                console.log(error);
                
            })
            // this.$refs.sse.open(0,1)


    },
    // 退出登录
    exit(){
      this.$confirm('确定退出吗', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
         this.$router.push('/')
        }).catch(() => {
                 
        });
     
    },
    onCollapse(){
           this.isCollapse=!this.isCollapse ;
          //  if(this.isCollapse){
          //    setTimeout(()=>{
          //    this.width="65px"

          //    },100)
          //  }else{
          //     this.width="200px"
          //  }
    },
    selectMenu(index){
       localStorage.setItem("menuIndex",index)
        
    }
  },
}
</script>
<style lang="less" scoped>
  .el-menu-vertical-demo:not(.el-menu--collapse) {
    width: 200px;
   height: calc(100% - 13px);
  }
.page_warppers{
  height: 100%;
  .container{
    display: flex;
    height: calc(100vh - 60px);
  }
   .el-header {
    background-color: #333;
    color: #333;
  }
  
  .el-aside {
    height: 100%;
    width: auto!important;
    background-color: #333;
    color: #333;
  }
  
  .el-main {
    height: 100%;
   padding-right: 0;

    background-color: #fff;
  }
  .header{
    height: 100%;
    display: flex;
    justify-content: flex-end;
    align-items: center;
  }
  .collapse{
    display:flex;
    justify-content: center;
    font-weight: 700;
    color: #fff;
    height: 13px;
    background-color: rgb(84, 92, 100);
    p{
    cursor:pointer; 
    }

  }
 .el-menu{
   border: none;
 }
  
}

</style>



